package com.jt1078.streamserver.manager;

import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

public class JT1078SessionManager {
    public static class JT1078Session {
        public int simLen = 0;
        public final String sim;
        public io.netty.channel.Channel deviceChannel; // 可选：用于对讲
        // 视频订阅
        public final Map<Integer, List<BlockingQueue<byte[]>>> subscribers = new ConcurrentHashMap<>();
        // 音频订阅
        public final Map<Integer, List<BlockingQueue<byte[]>>> audioSubscribers = new ConcurrentHashMap<>();
        // SPS/PPS...
        public final Map<Integer, byte[]> spsMap = new ConcurrentHashMap<>();
        public final Map<Integer, byte[]> ppsMap = new ConcurrentHashMap<>();
        public JT1078Session(String sim) { this.sim = sim; }
    }
    private static final Map<String, JT1078Session> sessions = new ConcurrentHashMap<>();
    public static JT1078Session getOrCreateSession(String sim) { return sessions.computeIfAbsent(sim, JT1078Session::new); }
    public static JT1078Session getSession(String sim) { return sessions.get(sim); }

    public static void printSessions() {
        System.out.println("当前会话数: " + sessions.size());
        for (Map.Entry<String, JT1078Session> entry : sessions.entrySet()) {
            System.out.println("SIM: " + entry.getKey() + ", 订阅数: " + entry.getValue().subscribers.size());
        }
    }
}
